﻿using System;
using System.Collections.Generic;
using System.Text;

namespace net.xBei.Helper
{
    public static class LogicHelper {
        public static bool All(this IEnumerable<Func<bool>> funcs) {
            foreach (var fun in funcs) {
                if (fun.Invoke() == false) {
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// 按顺序判断，只要一个方法是False就返回False
        /// </summary>
        /// <param name="funcs"></param>
        /// <returns></returns>
        public static bool All(params Func<bool>[] funcs)  {
            foreach (var fun in funcs) {
                if (fun.Invoke() == false) {
                    return false;
                }
            }
            return true;
        }
        public static bool All<T>(T value, params Func<T, bool>[] funcs) {
            foreach (var fun in funcs) {
                if (fun.Invoke(value) == false) {
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// 按顺序判断，只要一个方法是True就返回True
        /// </summary>
        /// <param name="funcs"></param>
        /// <returns></returns>
        public static bool Any(params Func<bool>[] funcs) {
            foreach (var fun in funcs) {
                if (fun.Invoke() == true) {
                    return true;
                }
            }
            return false;
        }
        public static bool Any<T>(T value, params Func<T, bool>[] funcs) {
            foreach (var fun in funcs) {
                if (fun.Invoke(value) == true) {
                    return true;
                }
            }
            return false;
        }
    }
}
